#ifndef TEMPRETURE_CONTROLLER_H
#define TEMPRETURE_CONTROLLER_H

#include "tempreture_Controller_global.h"
#include <QObject>
#include <QTimer>
#include "snap7.h"


class TEMPRETURE_CONTROLLER_EXPORT Tempreture_Controller: public QObject
{
    Q_OBJECT
public:
    explicit Tempreture_Controller(QObject *parent = nullptr);

    bool connectToPlc(QString);
    bool connectToPlc(){return connectToPlc(oldIP);}
    QString oldIP ;

    bool hotStart();
    void disconnectToPlc();

    bool setDigitalOutput(int outputPort,bool flag);
    bool readDigitalOutput(int outputPort);

    bool setDigitalMemery(uint16_t uAddr, int bit, bool flag);
    bool readDigitalMemery(uint16_t uAddr, int bit);

    bool writeFloat(uint16_t uAddr, float fValue, int nDb);
    float readFloat(uint16_t uAddr, float &fValue, int nDb);

    bool writeDB(uint16_t uAddr, int fValue, int nDb);
    int readDB(uint16_t uAddr, int nDb);


    //使能
    bool openPowerControl(bool flag);

    //设置功率控制
    void setPower(float power);

    //设置温度控制
    void setTempretrue(float tempretrue);

    float getCurrentPower();

    float getCurrentTempretrue();

    void enablePidControll(bool enable);


    void setCurve(QList<float> valueList, QList<float> timeList, QString type = "temp");

    QTimer *CurveTimer = new QTimer;


public slots:


private:
    TS7Client *client = new TS7Client;
    bool connectedFlag = false;
    float currentTempreTrue = -1;
    float currentPower = -1;

    QList<float> valueList;
    QList<float> timeList;
    QList<float> deltaTimeList;
    QString CurveType;

    int CurveCount = 0;
    float targetValue;




signals:
    void messageEmit(QByteArray);
    void plcErrOccuer();

};

#endif // TEMPRETURE_CONTROLLER_H
